package com.panda.cn.config.property;

import lombok.*;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @author: menghao.yan
 * @create: Created in 2021/7/1
 * @description: 自定义已知属性
 */
@Data
@AllArgsConstructor         //全参构造
@NoArgsConstructor          //无参构造
@Component
@ConfigurationProperties(prefix = "custom")
public class CustomProperty {
    
    protected Upload upload;
    
    @Data
    @AllArgsConstructor         //全参构造
    @NoArgsConstructor          //无参构造
    private static class Upload {
        private Os url;
        
    }
    
    @Data
    @AllArgsConstructor         //全参构造
    @NoArgsConstructor          //无参构造
    private static class Os {
        private String window;
        private String linux;
        private String mac;
    }
    
    /**
     * 得到上传url
     *
     * @return {@link String}
     */
    public String getUploadUrl() {
        Os os = this.upload.url;
        return isWinOs() ?  os.getWindow() : (isMacOs() ? os.getMac() : os.getLinux());
    }
    
    /**
     * 是window操作系统
     *
     * @return boolean
     */
    public boolean isWinOs(){
        String os = System.getProperty("os.name");
        if(os.toLowerCase().startsWith("win")) {
            return true;
        }
        return false;
    }
    
    /**
     * 是mac os操作系统
     *
     * @return boolean
     */
    public boolean isMacOs(){
        String os = System.getProperty("os.name");
        if(os.toLowerCase().startsWith("mac")) {
            return true;
        }
        return false;
    }
    
    /**
     * 是linux操作系统
     *
     * @return boolean
     */
    public boolean isLinuxOs(){
        String os = System.getProperty("os.name");
        if(os.toLowerCase().startsWith("linux")) {
            return true;
        }
        return false;
    }
}
